package com.softeem.idriveserver.dto;

import lombok.Data;
import lombok.experimental.Accessors;

/**
 * 统一返回结果的封装
 */
@Data
@Accessors(chain = true)  //开启链式编程
public class Result {

    /**状态码 0-成功  -1-失败*/
    private Integer code;
    /**附加文本消息*/
    private String msg;
    /**处理结果是否成功*/
    private boolean success;
    /**附加返回数据，例如查询结果集*/
    private Object data;
    /**总数据条数（分页用：计算总页数）*/
    private Long count;

    private Result(){}

    /**
     * 统一成功返回结果
     * @return
     */
    public static Result ok(){
        Result r = new Result();
        r.code = 0;
        r.msg = "执行成功";
        r.success = true;
        return r;
    }

    /**
     * 统一失败返回结果
     * @return
     */
    public static Result error(){
        Result r = new Result();
        r.code = -1;
        r.msg = "执行失败";
        r.success = false;
        return r;
    }

}
